package com.linwen.excise.niuke._60;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author wlw
 * @date 2023/3/16 11:21 PM
 */
public class _48从单向链表中删除指定值的节点 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int root = scanner.nextInt();
        int[] arr= new int[(n-1)*2];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scanner.nextInt();
        }
        int target = scanner.nextInt();
        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(root);
        for (int i = 0; i < arr.length; i+=2) {
            linkedList.add(linkedList.indexOf(arr[i+1])+1,arr[i]);
        }
        linkedList.remove(linkedList.indexOf(target));
        for (Integer integer : linkedList) {
            System.out.print(integer+" ");
        }
    }
}
